import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';
import 'dart:ffi';


typedef LoadLibraryFunc = Void Function();
typedef LoadLibrary = void Function();
/*
由于Flutter Web 上不支持 FFI, 如果打包或者web运行则报错,因此迁移到xsdk_flutter_plugin中来

XFFIUtils.loadLibrarySOFile() 等同android的方法: XFlutterPluginUtils.manualSystemLoadLibrary('objectbox-jni');

 */
abstract class XFFIUtils{


  /*
  flutter 调用android的System.loadLibrary
  手动加载.so文件,适用android 6.0, 如:objectbox-jni.so
   */
  static void loadLibrarySOFile(String libSoName){

    DynamicLibrary nativeLib = XFlutterUtils.isAndroid()
        ? DynamicLibrary.open(libSoName) // "libnative.so"
        : DynamicLibrary.process();

    final loadLibrary = nativeLib
        .lookupFunction<LoadLibraryFunc, LoadLibrary>('loadLibrary'); // 替换为您的动态链接库中的方法名称
    loadLibrary();
  }


}
